package com.kintreda.ieco_server.util.file;

import com.kintreda.ieco_server.util.file.io.ImgTools;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;

/**
 * 图片压缩线程
 * @author laizhengyu
 *
 */
public class FileCompressThread extends Thread {

	private String 	targetFile;
	
	public FileCompressThread(String targetFile) {
		this.targetFile = targetFile;
	}

	public void run() {
		
		try {
			System.out.println("------------------图片压缩执行中------------------");
			byte[] data = ImgTools.compress(ImgTools.readInByteArray(new File(targetFile)),0.4);
			FileUtils.writeByteArrayToFile(new File(targetFile), data);
			System.out.println("------------------图片压缩执行完成------------------");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
